package yuwenlong.receiver;

import android.content.Intent;
import android.content.IntentFilter;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;

import androidx.appcompat.app.AppCompatActivity;

import com.liao.liaowenlong.R;

public class Receiver2Activity extends AppCompatActivity implements View.OnClickListener {

    private EditText et_username;
    private EditText et_pwd;
    private Button btn_login;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_receiver2);
        initView();
    }

    private void initView() {
        et_username = (EditText) findViewById(R.id.et_username);
        et_pwd = (EditText) findViewById(R.id.et_pwd);
        btn_login = (Button) findViewById(R.id.btn_login);

        btn_login.setOnClickListener(this);
        myReceiver3 = new MyReceiver3();
        IntentFilter filter = new IntentFilter();
        filter.addAction("aa");
        registerReceiver(myReceiver3, filter);
    }

    @Override
    public void onClick(View v) {
        switch (v.getId()) {
            case R.id.btn_login:
                submit();
                break;
        }
    }

    MyReceiver3 myReceiver3;

    private void submit() {
        String username = et_username.getText().toString().trim();

        String pwd = et_pwd.getText().toString().trim();
        Intent intent = new Intent("aa");
        intent.putExtra("username", username);
        intent.putExtra("password", pwd);
        sendBroadcast(intent);
    }
}
